package cn.Alibaba.org.service.impl;

import cn.Alibaba.basic.service.impl.BaseServiceImpl;
import cn.Alibaba.basic.util.PageList;
import cn.Alibaba.org.domain.Department;
import cn.Alibaba.org.domain.Employee;
import cn.Alibaba.org.mapper.DepartmentMapper;
import cn.Alibaba.org.mapper.EmployeeMapper;
import cn.Alibaba.org.query.DepartmentQuery;
import cn.Alibaba.org.service.IDepartmentService;
import cn.Alibaba.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public void save(Employee employee) {

        super.save(employee);

        if (employee.getRole_id()!=null){
            employeeMapper.addEmployeeRole(employee.getId(),employee.getRole_id());
        }
    }

    @Override
    public void del(Long id) {

        employeeMapper.delEmployeeRole(id);

        super.del(id);
    }

    @Override
    public void update(Employee employee) {

        employeeMapper.delEmployeeRole(employee.getId());


        if (employee.getRole_id()!=null){
            employeeMapper.addEmployeeRole(employee.getId(),employee.getRole_id());
        }

        super.update(employee);


    }


    @Override
    public List<Employee> list(Long shopId) {
        return employeeMapper.list(shopId);
    }
}
